package solutions.leetcode.easy;

import solutions.lib.ListNode;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/swap-nodes-in-pairs/">24. 两两交换链表中的节点</a>
 */
public class Solution24 {

    public ListNode swapPairs(ListNode head) {
        ListNode rst = new ListNode();
        rst.next = head;
        ListNode p = rst;
        while (p.next != null && p.next.next != null) {
            ListNode t = p.next.next;
            p.next.next = t.next;
            t.next = p.next;
            p.next = t;
            p = t.next;
        }
        return rst.next;
    }

    public static void main(String[] args) {
        Solution24 solution = new Solution24();
    }
}
